<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
class YoulianController extends CommonController {
 
    	
  //===================================产品订单


    public function index() {
    	$s=M('youlian');
    	$show=$s->order('id desc')->select();

    
        foreach ($show as &$value) {
         $value['create_time']=date('Y-m-d',$value['create_time']);

        }
    
            
  $this->assign('show',$show);

    	
    	$this->display();
    }
      
  

    public function addshow(){
        if(IS_POST){
               $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     3145728 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
                $upload->savePath  =     ''; // 设置附件上传（子）目录
                // 上传文件
                $info   =   $upload->upload();
                if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{// 上传成功
                    $data["pic"]=$info["pic"]["savepath"].$info["pic"]["savename"];
                }

                $data['create_time'] = time();
                $data['name']=I('post.name');
                $data['url']=I('post.url');
                $data['type']=I('post.type');

            if(M('youlian')->add($data)){

                $this->success('添加成功',U('Youlian/index'));
                exit();
                }else{

                $this->success('添加失败',U('Youlian/index'));
                exit();
            }
         
        }

        $this->display();
    }



    public function update(){
        $id=I('id');
        $xinxi=M('youlian')->where('id='.$id)->find();
  
        $this->assign('xinxi',$xinxi);
        if(IS_POST){
       
        unlink("/Uploads/".$xinxi['pic']);  //删除图片文件

        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =     ''; // 设置附件上传（子）目录
        // 上传文件
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功
            $data["pic"]=$info["pic"]["savepath"].$info["pic"]["savename"];
        }

        $data['type']=I('post.type');
        $data['url']=I('post.url');
        $data['name']=I('post.name');
        $data['id']=I('id');


        if(M('youlian')->where('id='.$data['id'])->save($data)){

            $this->success('修改成功',U('Youlian/index'));
            exit();
        }else{
            $this->success('修改失败',U('Youlian/index'));
            exit();
        }

        
        }


        $this->display();   
    }



    public function delete(){
        $id = I('get.id');
        if(M('youlian')->where(array('id'=>$id))->delete()){
            $this->success('删除成功');
            exit();
        }else{
            $this->success('删除失败');
            exit();
        }




    }

    public function delete1(){
        $id = I('get.id');
        if(M('yuyue')->where(array('id'=>$id))->delete()){
            $this->success('删除成功');
            exit();
        }else{
            $this->success('删除失败');
            exit();
        }

        


    }

public function yuyue(){

      $m=M('yuyue');
    $count=$m->count();
        $Page =new \Think\Page($count,20);
        $Page -> setConfig('first','首页');
        $Page -> setConfig('last','末页');
        $Page -> setConfig('prev','上一页');
        $Page -> setConfig('next','下一页');
        $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END% </div> ');

        $show1 = $Page->show();

        $yuyue=$m->order("id desc")->limit($Page->firstRow, $Page->listRows)->select();


   $this->assign('page', $show1);
   $this->assign('yuyue', $yuyue);
 

   $this->display();

}


public function zhanshi(){


       $s=M('sylunbo');
        $show=$s->order("id desc")->select();

          $this->assign('show',$show);





    $this->display();
}

public function status(){
             $id = I('get.id');

     $xinxi=M('yuyue')->where('id='.$id)->find();


$this->assign('xinxi',$xinxi);    
   
    $this->display();

}

public function statuss(){
             $id = I('post.id');

     M('yuyue')->where('id='.$id)->setfield('status',$_POST['status']);

 $this->success('状态修改成功',U('Youlian/yuyue'));
    
   

}

public function gengxin(){


        if (I('get.id')) {
            $id=I('get.id');
        }else{
            $id=$_POST['dd'];
        }

            $xinxi=M('sylunbo')->where('id='.$id)->find();
            $this->assign('xinxi',$xinxi);
  
   

  
        if(IS_POST){
            if ($xinxi['pic']) {

                unlink("/Uploads/".$xinxi['pic']); 
     //删除图片文件
            }

            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     5145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            // 上传文件
            $info   =   $upload->upload();

    
          
            if(!$info) {// 上传错误提示错误信息
                      $this->error($upload->getError());
                unset( $data["pic"]);
            }else{// 上传成功
                $data["pic"]=$info["pic"]["savepath"].$info["pic"]["savename"];

            
            }

            

            if(M('sylunbo')->where("id=".$id)->save($data)){

                $this->redirect('Youlian/zhanshi');
                exit();
            }else{
                $this->success('轮播图修改失败',U('Youlian/zhanshi'));
                exit();
            }

        
        }else{
            $this->display(); 
        }




}





    public function dell(){

        $ids = $_POST['id'];

        $str="('".implode("','",$ids)."')";
      

        if (M("sylunbo")->where("id in ".$str)->delete()) {
            
            $this->redirect('Youlian/zhanshi');
        } else {
            $this->success('删除失败');
        }
    }

public function lunbo(){


        if(IS_POST){
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     553145728 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
                $upload->savePath  =     ''; // 设置附件上传（子）目录
                // 上传文件
                $info   =   $upload->upload();
                if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{// 上传成功
                    $data["pic"]=$info["pic"]["savepath"].$info["pic"]["savename"];
                  
                }

                

            if(M('sylunbo')->add($data)){

                $this->redirect('Youlian/zhanshi');
                exit();
                }else{
                $this->success('添加轮播图失败',U('Youlian/zhanshi'));
                exit();
            }
         
        }


    $this->display();
}











  

}

?>